package com.ruoyi.web.controller.webs.ky450;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.ky450.domain.TargetBaseInfo;
import com.ruoyi.ky450.dto.TargetAttachmentCondition;
import com.ruoyi.ky450.dto.TreeCommonCondition;
import com.ruoyi.ky450.service.IFixedFacilityElementInfoService;
import com.ruoyi.ky450.service.ITargetBaseInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 目标基本信息Controller
 *
 * @author ruoyi
 * @date 2025-01-16
 */

@Api(tags = "目标管理（免登录）")
@RestController
@RequestMapping("/webs/targetBaseInfo")
public class TargetBaseInfoController extends BaseController
{
    @Autowired
    private ITargetBaseInfoService targetBaseInfoService;

    @Autowired
    private IFixedFacilityElementInfoService fixedFacilityElementInfoService;

    /**
     * 查询目标基本信息列表
     */
    //@PreAuthorize("@ss.hasPermi('system:info:list')")
    @GetMapping("/list")
    public TableDataInfo list(TargetBaseInfo targetBaseInfo)
    {
        startPage();
        List<TargetBaseInfo> list = targetBaseInfoService.selectTargetBaseInfoList(targetBaseInfo);
        return getDataTable(list);
    }

    /**
     * 导出目标基本信息列表
     */
    //@PreAuthorize("@ss.hasPermi('system:info:export')")
    //@Log(title = "目标基本信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TargetBaseInfo targetBaseInfo)
    {
        List<TargetBaseInfo> list = targetBaseInfoService.selectTargetBaseInfoList(targetBaseInfo);
        ExcelUtil<TargetBaseInfo> util = new ExcelUtil<TargetBaseInfo>(TargetBaseInfo.class);
        util.exportExcel(response, list, "目标基本信息数据");
    }

    /**
     * 获取目标基本信息详细信息
     */
    //@PreAuthorize("@ss.hasPermi('system:info:query')")
    @ApiOperation("获取目标基本信息")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(targetBaseInfoService.selectTargetBaseInfoById(id));
    }

    /**
     * 新增目标基本信息
     */
    //@PreAuthorize("@ss.hasPermi('system:info:add')")
    //@Log(title = "目标基本信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TargetBaseInfo targetBaseInfo)
    {
        return toAjax(targetBaseInfoService.insertTargetBaseInfo(targetBaseInfo));
    }

    /**
     * 修改目标基本信息
     */
    //@PreAuthorize("@ss.hasPermi('system:info:edit')")
    //@Log(title = "目标基本信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TargetBaseInfo targetBaseInfo)
    {
        return toAjax(targetBaseInfoService.updateTargetBaseInfo(targetBaseInfo));
    }

    /**
     * 删除目标基本信息
     */
    //@PreAuthorize("@ss.hasPermi('system:info:remove')")
    //@Log(title = "目标基本信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(targetBaseInfoService.deleteTargetBaseInfoByIds(ids));
    }

    @ApiOperation("固定设施列表（树形结构）")
    @GetMapping("/fixedFacilityListTree")
    public AjaxResult fixedFacilityListTree(@Validated @ModelAttribute final TreeCommonCondition condition)
    {
        return AjaxResult.success(targetBaseInfoService.fixedFacilityListTree(condition));
    }

    @ApiOperation("装备列表（树形结构）")
    @GetMapping("/equipListTree")
    public AjaxResult equipListTree(@Validated @ModelAttribute final TreeCommonCondition condition)
    {
        return AjaxResult.success(targetBaseInfoService.equipListTree(condition));
    }

    @ApiOperation("获取固定设施要素信息")
    @GetMapping(value = "/getFixedFacility/{id}")
    public AjaxResult getFixedFacility(@PathVariable("id") Long id)
    {
        return AjaxResult.success(targetBaseInfoService.getFixedFacility(id));
    }

    @ApiOperation("获取装备信息")
    @GetMapping(value = "/getEquip/{id}")
    public AjaxResult getEquip(@PathVariable("id") Long id)
    {
        return AjaxResult.success(targetBaseInfoService.getEquip(id));
    }

    @ApiOperation("获取目标附件")
    @GetMapping(value = "/getTargetAttachment")
    public AjaxResult getTargetAttachment(@Validated @ModelAttribute final TargetAttachmentCondition condition)
    {
        return AjaxResult.success(targetBaseInfoService.getTargetAttachment(condition));
    }
}
